< previous page page_391 next page >

Page 391
If this seems like a lot of work for little benefit, you are right. Performing a matrix/vector multiplication takes six additions, nine multiplications, and some overhead for running two For loops. This is a good deal more work than the two additions it would take to directly add Tx and Ty to the point's coordinates.
The real advantage of this method comes when you combine transformations. You will see the power of homogeneous coordinates a little later in the section ''Composing Transformations."
Scaling
Just as you can represent translation using a matrix, you can represent scaling by a factor of Sx in the X direction and Sy in the Y direction with the matrix:
e10a6a0a59f035e870d90cca05b85fce.gif
 z0411-01.gif
When you multiply the point [x, y, 1] with this matrix you get:
e10a6a0a59f035e870d90cca05b85fce.gif
 z0411-02.gif
The resulting vector [x * Sx, y * Sy, 1] correctly represents the point (x, y) after it has been scaled to (x * Sx, y * Sy).
Rotation
You can represent rotation by an angle q with the transformation matrix:
e10a6a0a59f035e870d90cca05b85fce.gif
 z0411-03.gif
Multiplying the vector [x, y, 1] by this matrix, you get [x * Cos(q) y * Sin(q), x * Sin(q) + y * Cos(q), 1]. This agrees with the previous result for rotating a point (x, y) by the angle q to the point (x * Cos(q) y * Sin(q), x * Sin(q) + y * Cos(q)).
Inverse Transformations
Each of these basic transformations has a simple inverse that undoes whatever operation was performed by the transformation. If you apply a transformation to an object and then apply the transformation's inverse, the object ends up in its original position.
The inverse of a translation by distance Tx in the X direction and Ty in the Y direction is simply a translation by distances Tx and Ty. The transformation matrix for this operation is:

 
< previous page page_391 next page >